
function humanFileSize(size) 
{
    var i = Math.floor( Math.log(size) / Math.log(1024) );
    return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}        
function addformbookupload()
{

    //console.log(config);
    $("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addUlPlg featureclass">'+dataform['bookupload']+"</div>");
    var rownow=rowdiv;
    
   var arrayexitfile=new Array('zave','zavec','zavem'); 
   var rownumdata=0;
   for(var irow=1;irow<4;irow++)
   {  
  var irowset=irow; 

  $('#feature'+rownow+' .zav'+irowset).iuploader({
         'link':serviceinfo+'iuploadfile',
         'accept':arrayexitfile[rownumdata],
         'group':irowset,
         'type':[arrayexitfile[rownumdata]],
         'onStartUpload':function(setting){
         
         
         },
         'load':$('#feature'+rownow+' .zav'+irowset+' .clTxtW.fs03'),
         'isimg':false,
         'onUploadFinish':function(filename,filelink,setting){
           
          $("#fileid-"+setting.id).val(setting.fileid);
          $("#fileold-"+setting.id).val(setting.fileold);

          $('#feature'+rownow+' .zav'+setting.group+' .nameZavFile').html('<a href="'+filelink+'" target="_bank">'+setting.fileold+'</a>');
          
          $('#feature'+rownow+' .zav'+setting.group+' .sizeZavFile').html(humanFileSize(setting.size));
         

         


         }
   });
   
  
          rownumdata++;
   }
   
   
    $('#feature'+rownow+' .zav1 .deletebtn').click(function() {
   
   $('#feature'+rownow+' .zav1 .nameZavFile').html('');
   $('#feature'+rownow+' .zav1 .sizeZavFile').html('');
   $('#feature'+rownow+' .zav1 input[name="fileold[]"]').val('');
   $('#feature'+rownow+' .zav1 input[name="fileid[]"]').val('');
   $('#feature'+rownow+' .zav1 input[name="filelink[]"]').val('');

   
   });
   
   $('#feature'+rownow+' .zav2 .deletebtn').click(function() {
   
   $('#feature'+rownow+' .zav2 .nameZavFile').html('');
   $('#feature'+rownow+' .zav2 .sizeZavFile').html('');
   $('#feature'+rownow+' .zav2 input[name="fileold[]"]').val('');
   $('#feature'+rownow+' .zav2 input[name="fileid[]"]').val('');
   $('#feature'+rownow+' .zav2 input[name="filelink[]"]').val('');

   
   });
   
   $('#feature'+rownow+' .zav3 .deletebtn').click(function() {
   
   $('#feature'+rownow+' .zav3 .nameZavFile').html('');
   $('#feature'+rownow+' .zav3 .sizeZavFile').html('');
   $('#feature'+rownow+' .zav3 input[name="fileold[]"]').val('');
   $('#feature'+rownow+' .zav3 input[name="fileid[]"]').val('');
   $('#feature'+rownow+' .zav3 input[name="filelink[]"]').val('');

   
   });
   
   $('#feature'+rownow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();
    
   });
   
   

    
    
    
    
    rowdiv++;

}
function saveformbookupload(id,plugid)
{
var obj={};
if($("#"+id+' .zav1 input[name="fileid[]"]').val()!=""&&$("#"+id+' .zav2 input[name="fileid[]"]').val()!=""&&$("#"+id+' .zav3 input[name="fileid[]"]').val()!="" )
{
obj={plugid:plugid,zave:$("#"+id+' .zav1 input[name="fileid[]"]').val(),zavec:$("#"+id+' .zav2 input[name="fileid[]"]').val(),zavem:$("#"+id+' .zav3 input[name="fileid[]"]').val()};
}

return obj;

}
function getformbookupload(arraydata)
{
var code="";
if(arraydata['filezave']['filename']&&arraydata['filezavec']['filename']&&arraydata['filezavem']['filename'])    
{
code = '<div class="ldIt wrpDlZaveLd clBg4">\n';
code += '<h2 class="clTxt2 fs04 boldGen">Download ZAVE File</h2>\n';
code += '<div class="wrpOutDlZaveLd">\n';
code += '<div class="wrpInDlZaveLd clearfix">\n';
code += '<div class="wrpOutDlZave">\n';
code += '<div class="wrpDlZave">\n';
code += '<a href="'+arraydata['filezave']['newpath']+'">\n';
code += '<div class="btnIco dlZaveLd">\n';
code += '<span class="ico2 icoDZavelLd"></span>\n';
code += '</div>\n';
code += '<div class="btnDlZaveFile">\n';
code += '<span class="clTxtW">ZAVE</span>\n';
code += '</div>\n';
code += '</a>\n';
code += '</div>\n';
code += '<div class="desFileDlZaveLd">\n';
code += '<span class="fileName cutTxt">'+arraydata['filezave']['filename']+'</span>\n';
code += '<span class="fileSize cutTxt">'+humanFileSize(arraydata['filezave']['size'])+'</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrpOutDlZave">\n';
code += '<div class="wrpDlZave">\n';
code += '<a href="'+arraydata['filezavec']['newpath']+'">\n';
code += '<div class="btnIco dlZaveLd">\n';
code += '<span class="ico2 icoDZavelLd"></span>\n';
code += '</div>\n';
code += '<div class="btnDlZaveFile">\n';
code += '<span class="clTxtW">ZAVEC</span>\n';
code += '</div>\n';
code += '</a>\n';
code += '</div>\n';
code += '<div class="desFileDlZaveLd">\n';
code += '<span class="fileName cutTxt">'+arraydata['filezavec']['filename']+'</span>\n';
code += '<span class="fileSize cutTxt">'+humanFileSize(arraydata['filezavec']['size'])+'</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrpOutDlZave">\n';
code += '<div class="wrpDlZave">\n';
code += '<a href="'+arraydata['filezavem']['newpath']+'">\n';
code += '<div class="btnIco dlZaveLd">\n';
code += '<span class="ico2 icoDZavelLd"></span>\n';
code += '</div>\n';
code += '<div class="btnDlZaveFile">\n';
code += '<span class="clTxtW">ZAVEM</span>\n';
code += '</div>\n';
code += '</a>\n';
code += '</div>\n';
code += '<div class="desFileDlZaveLd">\n';
code += '<span class="fileName cutTxt">'+arraydata['filezavem']['filename']+'</span>\n';
code += '<span class="fileSize cutTxt">'+humanFileSize(arraydata['filezavem']['size'])+'</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';
}

code="";
return code;

}
function editformbookupload(datarow)
{
    if(datarow.fileid!="0")
    {
     addformbookupload();
     var rownow= rowdiv-1;
      
     //  $('#feature'+rownow+' input[name="fileid[]"]').val(datarow.fileid);
//       $('#feature'+rownow+' .fileName').html('<a href="'+datarow.file.newpath+'" target="'+datarow.file.newpath+'">'+datarow.file.filename+'</a>');
//       $('#feature'+rownow+' .btnIco.upAddIco').hide();
//       $('#feature'+rownow+' .ico2.icoCrtGrn').show();
//       $('#feature'+rownow+' input[name="detail[]"]').val(datarow.detail);

          $('#feature'+rownow+' .zav1 input[name="fileid[]"]').val(datarow.zave);         
          $('#feature'+rownow+' .zav1 input[name="fileold[]"]').val(datarow.filezave.filename);         


          $('#feature'+rownow+' .zav1 .nameZavFile').html('<a href="'+datarow.filezave.newpath+'" target="_bank">'+datarow.filezave.filename+'</a>');
          
          $('#feature'+rownow+' .zav1 .sizeZavFile').html(humanFileSize(datarow.filezave.size));
          
          
          
          $('#feature'+rownow+' .zav2 input[name="fileid[]"]').val(datarow.zavec);         
          $('#feature'+rownow+' .zav2 input[name="fileold[]"]').val(datarow.filezavec.filename);         


          $('#feature'+rownow+' .zav2 .nameZavFile').html('<a href="'+datarow.filezavec.newpath+'" target="_bank">'+datarow.filezavec.filename+'</a>');
          
          $('#feature'+rownow+' .zav2 .sizeZavFile').html(humanFileSize(datarow.filezavec.size));
          
                                                           
          
          $('#feature'+rownow+' .zav3 input[name="fileid[]"]').val(datarow.zavem);         
          $('#feature'+rownow+' .zav3 input[name="fileold[]"]').val(datarow.filezavemfilename);         


          $('#feature'+rownow+' .zav3 .nameZavFile').html('<a href="'+datarow.filezavem.newpath+'" target="_bank">'+datarow.filezavem.filename+'</a>');
          
          $('#feature'+rownow+' .zav3 .sizeZavFile').html(humanFileSize(datarow.filezavem.size));
          
          
          $('#feature'+rownow+' .clTxtW.fs03').hide();
       
       
       
       
       
    }
       
}